package com.example.greenapp.activity;

import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.example.greenapp.R;
import com.example.greenapp.fragment.Main_Fragment1;
import com.example.greenapp.fragment.Main_Fragment2;
import com.example.greenapp.fragment.Main_Fragment3;
import com.example.greenapp.fragment.Main_Fragment4;
import com.example.greenapp.util.Contant;

public class MainActivity extends AppCompatActivity {

    FragmentTabHost tabHost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        init_FragMent();//主布局视图

    }

    private void init_FragMent() {
        tabHost = findViewById(R.id.tabHost);
        tabHost.setup(this,getSupportFragmentManager(),R.id.main_frag_lay);

        for (int i = 0; i < 4; i++) {
            TabHost.TabSpec tabSpec = tabHost.newTabSpec(i+"");
            View view = getLayoutInflater().inflate(R.layout.bottom_item,null);

            ImageView fot_img = view.findViewById(R.id.fot_img);
            fot_img.setImageResource(Contant.BOOTOM_IMG[i]);

            TextView fot_text = view.findViewById(R.id.fot_text);
            fot_text.setText(Contant.BOOTOM_TEXT[i]);

            tabSpec.setIndicator(view);//添加视图

           switch(i){
               case 0:
                   tabHost.addTab(tabSpec,Main_Fragment1.class,null);
                   break;
               case 1:
                   tabHost.addTab(tabSpec,Main_Fragment2.class,null);
                   break;
               case 2:
                   tabHost.addTab(tabSpec,Main_Fragment3.class,null);
                   break;
               case 3:
                   tabHost.addTab(tabSpec,Main_Fragment4.class,null);
                   break;
               default:
                   break;
           }

        }
    }
}
